package com.subsequent.service.impl;

import com.subsequent.entity.Notice;
import com.subsequent.mapper.NoticeMapper;
import com.subsequent.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class NoticeServiceImpl implements NoticeService {

    @Autowired
    private NoticeMapper noticeMapper;

    @Override
    public List<Notice> selectByCondition(String title, Integer status, String startTime, String endTime) {
        return noticeMapper.selectByCondition(title, status, startTime, endTime);
    }

    @Override
    public int countByCondition(String title, Integer status, String startTime, String endTime) {
        return noticeMapper.countByCondition(title, status, startTime, endTime);
    }

    @Override
    public Notice selectById(Integer noticeId) {
        return noticeMapper.selectById(noticeId);
    }

    @Override
    public int insert(Notice notice) {
        Date now = new Date();
        notice.setCreatedAt(now);
        notice.setUpdatedAt(now);
        return noticeMapper.insert(notice);
    }

    @Override
    public int update(Notice notice) {
        notice.setUpdatedAt(new Date());
        return noticeMapper.update(notice);
    }

    @Override
    public int deleteById(Integer noticeId) {
        return noticeMapper.deleteById(noticeId);
    }
}